package com.mxpio.erp.common.plm.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.policy.ResCodeGeneratorPolicy;
import com.mxpioframework.filestorage.entity.MxpioFileInfo;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import com.mxpioframework.security.entity.Dept;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "MB_ERP_PLM_PROJECT_INFO")
@Schema(description = "项目列表信息")
public class ProjectInfo extends BaseEntity {

    private static final long serialVersionUID=1L;

    /**项目编码*/
    @Id
    @Column(name = "PRO_CODE_")
    @Generator(policy = ResCodeGeneratorPolicy.class)
    @Schema(description = "项目编码")
    private String proCode;

    /**项目名称*/
    @Column(name = "PRO_NAME_")
    @Schema(description = "项目名称")
    private String proName;

    /**状态*/
    @Column(name = "STATUS_")
    @Schema(description = "状态")
    @Dict(dicCode = "ERP_PROJECT_INFO_STATUS")//0延期  1正常
    private String status;

    @Column(name = "OVERDUE_DAY_")
    @Schema(description = "逾期天数")
    private Long overdueDay;

    /**进度*/
    @Column(name = "SCHEDULE_")
//    @Transient
    @Schema(description = "进度")
    private BigDecimal schedule;

//    /**项目文件夹*/
//    @Column(name = "PRO_FILE_PATH_")
//    @Schema(description = "项目文件夹")
//    private String proFilePath;

    /**项目状态*/
    @Column(name = "PRO_STATUS_")
    @Schema(description = "项目状态")
    @Dict(dicCode = "ERP_PROJECT_INFO_PROSTATUS")
    private String proStatus;

//    /**里程碑阶段*/
//    @Column(name = "MILESTONE_PHASE_")
//    @Schema(description = "里程碑阶段")
//    private String milestonePhase;

    /**优先级*/
    @Column(name = "PRIORITY_")
    @Schema(description = "优先级")
    @Dict(dicCode = "ERP_PROJECT_INFO_PRIORITY")// 10低级 20中级 30高级
    private String priority;

    /**项目来源*/
    @Column(name = "PRO_SOURCE_")
    @Schema(description = "项目来源")
    @Dict(dicCode = "ERP_PROJECT_INFO_PRO_SOURCE") // 0内部 1外部
    private String proSource;

    /**项目类型*/
    @Column(name = "PRO_TYPE_")
    @Schema(description = "项目类型")
    @Dict(dicCode = "ERP_PROJECT_INFO_PRO_TYPE")
    private String proType;

    /**项目经理*/
    @Column(name = "PRO_LEADER_")
    @Schema(description = "项目经理")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String proLeader;

    /**项目秘书*/
    @Column(name = "PRO_SECRETARY_")
    @Schema(description = "项目秘书")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String proSecretary;

    /**计划开始时间*/
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "计划开工时间")
    @Column(name = "PLAN_START_TIME_")
    private java.util.Date planStartTime;
    /**计划结束时间*/
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Schema(description = "计划结束时间")
    @Column(name = "PLAN_END_TIME_")
    private java.util.Date planEndTime;

    /**实际开始日期*/
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Schema(description = "实际开始日期")
    @Column(name = "ACTUAL_START_TIME_")
    private Date actualStartTime;
    /**实际结束时间*/
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @Schema(description = "实际结束日期")
    @Column(name = "ACTUAL_END_TIME_")
    private Date actualEndTime;

    /**工期*/
    @Column(name = "DURATION_")
    @Schema(description = "工期")
    private BigDecimal duration;

//    /**项目交付物类型*/
//    @Column(name = "DELIVERABLES_TYPE_")
//    @Schema(description = "项目交付物类型")
//    private String deliverablesType;

    /**项目预算*/
    @Column(name = "PRO_BUDGET_")
    @Schema(description = "项目预算")
    private BigDecimal proBudget;

    /**项目范围*/
    @Column(name = "PRO_RANGE_",columnDefinition="TEXT")
    @Schema(description = "项目范围")
    private String proRange;

    /**项目目标*/
    @Column(name = "PRO_TARGET_",columnDefinition="TEXT")
    @Schema(description = "项目目标")
    private String proTarget;

    /**项目章程*/
    @Column(name = "RULES_")
    @Schema(description = "项目章程")
    @Dict(dicCode = "fileNo", dicEntity = MxpioFileInfo.class, dicText = "fileName")
    private String rules;

    /**是否作为模板*/
    @Column(name = "IS_TEMPLATE_")
    @Schema(description = "是否作为模板")
    private String isTemplate;

    /**存交付物的编码*/
    @Transient
    private List<ProjectDeliverable> projectDeliverable;

    @Transient
    private ProjectInfoChange projectInfoChange;

    /**审批状态*/
    @Transient
    @Schema(description = "审批状态")
    @Dict(dicCode = "ERP_PLM_PROJECT_BPMN_STATUS")
    private String bpmnStatus;
//
//    /**审批实例ID*/
//    @Column(name = "PROCESS_INSTANCE_ID_")
//    @Schema(description = "审批实例ID")
//    @Generator
//    private String processInstanceId;

//    @Column(name = "IS_PRO_")
//    @Schema(description = "是否点击立项")
//    @Dict(dicCode = "MB_SYSTEM_YES_NO") //1:是；0:否
//    private String isPro;

    /**申请审批原因*/
    @Transient
//    @Column(name = "REASON_",columnDefinition="TEXT")
    @Schema(description = "申请原因")
    private String reason;

    @Transient
    @Schema(description = "任务总数")
    private Integer taskCount;

    @Transient
    @Schema(description = "新增任务数")
    private Integer taskCountNew;

    @Transient
    @Schema(description = "执行中任务数")
    private Integer taskCountExecute;

    @Transient
    @Schema(description = "已完成任务数")
    private Integer taskCountFinish;

    @Transient
    @Schema(description = "已关闭任务数")
    private Integer taskCountShutDown;

//    @Transient
//    @Schema(description = "逾期任务数")
//    private Integer taskCountLate;

    @Transient
    @Schema(description = "项目交付物数量")
    private Integer infoDeliverableCount;

    @Transient
    @Schema(description = "项目成员")//四个角色下的成员总数
    private Integer infoMember;

    @Transient
    @Schema(description = "任务负责人数量")//任务负责人的数量
    private Integer taskHeads;

    @Transient
    @Schema(description = "项目计划进度")
    private BigDecimal infoPlanProgress;

    @Column(name = "INFO_DEPT_ID_")
    @Schema(description = "项目所属部门")
    @Dict(dicCode = "deptCode", dicEntity = Dept.class, dicText = "deptName")
    private String infoDeptId;


    /**
     * 以下是逾期项目展示所使用的字段
     */
    @Transient
    @Schema(description = "任务编码")
    private String taskCode;

    @Transient
    @Schema(description = "任务名称")
    private String taskName;

    @Transient
    @Column(name = "HEAD_")
    @Schema(description = "任务负责人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String head;

}
